#include <linux/module.h>
#include <linux/init.h>


//MODULE_DESCRIPTION("Example module illustrating the kernel timer.");
//MODULE_AUTHOR("chunli.che");
//MODULE_LICENSE("GPL");

#define DELAY   HZ
struct timer_list my_timer;
static int times=0;
static void my_timer_func(unsigned long ptr)
{
	printk(KERN_INFO "my_timer_func ptr = %ld\n", ptr);
    if (times++ <= 3) {
        /* otherwise it's will run perminant and it's not be rmmod. */
        my_timer.expires = jiffies + DELAY*3;
        add_timer(&my_timer);
    }
}

static int __init timer_init(void)
{

	printk(KERN_INFO "init one timer\n");

	init_timer(&my_timer);
	my_timer.function = my_timer_func;
	my_timer.data = 1;
	my_timer.expires = jiffies + DELAY;
	add_timer(&my_timer);

	return 0;
}

static void __exit timer_cleanup(void)
{
	printk(KERN_INFO "unloading timer...\n");
	del_timer(&my_timer);
}

module_init(timer_init);
module_exit(timer_cleanup);
